package com.chennan.algorithm.offer.fore;

import javax.xml.transform.Source;
import java.util.Stack;

/**
 * @author chennan
 * @create 2022-04
 *
 */
public class OneAddHundred {
    public static void main(String[] args) {
//        System.out.println(add(1));
        System.out.println(matchBrackets("{}{[]}{([])}(){}()"));
    }

    public static int add(int i){
        if(i==100){
            return i;
        }
        return add(i+1)+i;
    }

    public static boolean matchBrackets(String str){
        int length = str.length();
        Stack<String> stack = new Stack<>();
        for (int i = 0; i < length; i++) {
            String c = str.charAt(i)+"";
            if(c.equals("{")||c.equals("(")||c.equals("[")){
                stack.push(c);
            }else{
                if(!switchS(c).equals(stack.pop())){
                    return false;
                }
                if(stack.size()>length/2){
                    return false;
                }
            }
        }
        if(stack.size()==0){
            return true;
        }
        return false;
    }

    public static String switchS(String str){
        switch (str){
            case "}":
                return "{";
            case ")":
                return "(";
            case "]":
                return "[";
        }
        return "";
    }


}
